package com.group.orderproject.Service;

import com.group.orderproject.Dao.DishDao;
import com.group.orderproject.pojo.Dish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishService {
    @Autowired
    DishDao dishDao;
    public List<Dish> findAll(){
        return dishDao.findAll();
    }
    public Integer selectAll(String DishName){
        return dishDao.selectAllNum(DishName);
    }
    public List<Dish> selectBy(String DishName){
        DishName="%"+DishName+"%";
        return dishDao.selectByName(DishName);
    }
    public List<Dish> selectPage(Integer pageNum,Integer pageSize,String DishName){
        pageNum=(pageNum-1)*pageSize;
        return dishDao.selectPage(pageNum,pageSize,DishName);
    }

    public int save(Dish dish){
        if(dish.getId()==null){
            return dishDao.insert(dish);
        }else {
            return dishDao.update(dish);
        }
    }
    public int deleteById(int id){
        return dishDao.deleteById(id);
    }
    public int deleteByIds(List<Integer> ids){
        String idSet="";
        for (int i=0;i<ids.size();i++){
            idSet+=ids.get(i);
            if(i!=ids.size()-1){
                idSet+=",";
            }
        }
        return dishDao.deleteByIds(idSet);
    }
}
